package com.xlh.adapter;

import java.util.List;

import com.xlh.Utils.Constant;
import com.xlh.Utils.FUti;
import com.xlh.bean.GameServerBean;
//import com.xlh.outside.GameServerListActivity;
import com.xlh.outside.R;
import com.xlh.outside.ServerListActivity;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
 
/**
 * 自定义适配器类
 * =
 *
 */
public class GameServerListAdapter extends BaseAdapter {
    private List<GameServerBean> mList;
    public Context mContext;

        public GameServerListAdapter(Context pContext, List<GameServerBean> pList) {
            this.mContext = pContext;
            this.mList = pList;
    }
 
    @Override
    public int getCount() {
        return mList.size();
    }
 
    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }
 
    @Override
    public long getItemId(int position) {
        return position;
    }
    /**
     * 下面是重要代码
     */
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater _LayoutInflater = LayoutInflater.from(mContext);
        convertView=_LayoutInflater.inflate(R.layout.game_server_list_item, null);
        if(convertView!=null) {

            TextView btnInGame = (TextView)convertView.findViewById(R.id.btn_in_game);
            int w =  ((ServerListActivity)mContext).getWindowManager().getDefaultDisplay().getWidth();
            //GradientDrawable drawable = (GradientDrawable) btnInGame.getBackground();

            //边框
            //drawable.setStroke(FUti.dip2px(convertView.getContext(),1), Color.parseColor("#000000"));
            //无论什么颜色设置边框透明
           // drawable.setAlpha(0);
            ViewGroup.LayoutParams butLp = btnInGame.getLayoutParams();
            //vLparam.width = FUti.dip2px(context,parentWidth/gridConums);
            butLp.width = FUti.dip2px(mContext,w/2);
            butLp.height  = FUti.dip2px(mContext,32);



            btnInGame.setText(mList.get(position).getName());

            btnInGame.setOnClickListener(new View.OnClickListener() {  
                
                @Override  
                public void onClick(View v) {  
                	 ((ServerListActivity)mContext).runGame(position);
                }  
            });  
            

            
            

    }
        return convertView;
    }
}